local haozhu = fk.CreateSkill{
    name = "wk_heg__haozhu",
}

Fk:loadTranslationTable{
  ["wk_heg__haozhu"] = "豪注",
  [":wk_heg__haozhu"] = "其他角色每回合内体力值首次变化后，你可获得其一张牌并交给其一张牌，然后你<a href=':DoGiveDeputy'>遣调</a>此武将牌于其至其回合结束。",

  ["#wk_heg__haozhu-slash"] = "豪注：将一张牌当【杀】对 %src 使用",

  ["$wk_heg__haozhu1"] = "吾有密信，特来献于将军。",
  ["$wk_heg__haozhu2"] = "将军若不信，可亲自验看！",
}

local H = require "packages.ol_hegemony.util"
local HG = require "packages.new_heg_diy_my.util"


haozhu:addEffect(fk.HpChanged,{
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if target == player or not player:hasSkill(haozhu.name) then return false end
    local changehp_events = player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
      return e.data.who == target
    end, Player.HistoryTurn)
    return #changehp_events == 1 and changehp_events[1].data == data and not target:isNude()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToChooseCards(player,{
      target = target,
      min = 1,
      max = 1,
      flag = "he",
      skill_name = haozhu.name,
    })
    room:obtainCard(player, cards, false, fk.ReasonPrey)
    if not player:isNude() then
      local cards2 = room:askToChooseCards(player,{
          target = player,
          min = 1,
          max = 1,
          flag = "he",
          skill_name = haozhu.name,
      })
      room:obtainCard(target, cards2, false, fk.ReasonGive)
    end
    if player.general == "wk_heg__kanze" or player.deputyGeneral == "wk_heg__kanze" then
      if player.dead or target.dead then return end
      local isDeputy = H.inGeneralSkills(player, haozhu.name)
      if isDeputy and target:getMark("@wk_give_deputy") == 0 then
        HG.DoGiveDeputy(room, player, target, "wk_heg__kanze", player.kingdom, isDeputy == "d")
      end
    end
  end,
})

haozhu:addEffect(fk.TurnEnd,{
  is_delay_effect = true,
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return player.room.current == player and player:getMark("@wk_give_deputy") == "wk_heg__kanze"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    HG.StopGiveDeputy(player.room, player, haozhu.name)
  end,
})

return haozhu